﻿using System;
using System.Collections.Generic;
using System.Web;
using ihongma.Web.UI;
using ihongma.Common;
using ihongma;
using System.Text;
using System.Web.SessionState;
namespace ihongma.Web.tools
{
    public class ajax_order : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            //取得处事类型
            string action = DTRequest.GetQueryString("action");

            switch (action)
            {
                case "add": //发布留言
                    feedback_add(context);
                    break;
            }

        }

        #region 发布留言================================
        private void feedback_add(HttpContext context)
        {
            StringBuilder strTxt = new StringBuilder();
            
           // ihongma.BLL.Order bll = new ihongma.BLL.Order();
            Model.Order model = new Model.Order();

            string _code = DTRequest.GetFormString("txtCode");
            //string _title = DTRequest.GetFormString("txtTitle");
            //string _content = DTRequest.GetFormString("txtContent");
            //string _user_name = DTRequest.GetFormString("txtUserName");
            //string _user_tel = DTRequest.GetFormString("txtUserTel");
            //string _user_qq = DTRequest.GetFormString("txtUserQQ");
            //string _user_email = DTRequest.GetFormString("txtUserEmail");
            string name = DTRequest.GetFormString("texname");
            string email = DTRequest.GetFormString("txtemail");
            string tel =DTRequest.GetFormString("txttel") ;
            string zipcode = DTRequest.GetFormString("txtzipcode");
            string pcname = DTRequest.GetFormString("txtpcname");
            string sum = DTRequest.GetFormString("txtnum");
            string counet = DTRequest.GetFormString("txtcounet");
            string address = DTRequest.GetFormString("txtaddress");
            string radio = DTRequest.GetFormString("radio");
            DateTime addtiem = DateTime.Now;

           // ihongma.Model.Order model = new ihongma.Model.Order();
         

            ihongma.BLL.Order bll = new ihongma.BLL.Order();
            //校检验证码
            if (string.IsNullOrEmpty(_code))
            {
                context.Response.Write("{msg:0, msgbox:\"对不起，请输入验证码！\"}");
                return;
            }
            if (context.Session[DTKeys.SESSION_CODE] == null)
            {
                context.Response.Write("{msg:0, msgbox:\"对不起，系统找不到生成的验证码！\"}");
                return;
            }
            if (_code.ToLower() != (context.Session[DTKeys.SESSION_CODE].ToString()).ToLower())
            {
                context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致！\"}");
                return;
            }
            model.name = name;
            model.email = email;
            model.tel = tel;
            model.zipcode = zipcode;
            model.pcname = pcname;
            model.sum = sum;
            model.counet =address+"@"+radio+"@"+counet;
            model.addtiem = addtiem;

            //model.title = _title;
            //model.content = Utils.ToHtml(_content);
            //model.user_name = _user_name;
            //model.user_tel = _user_tel;
            //model.user_qq = _user_qq;
            //model.user_email = _user_email;
            //model.add_time = DateTime.Now;
            //model.is_lock = 1; //不需要审核，请改为0
            if (bll.Add(model))
            {
                context.Response.Write("{msg: 1, msgbox: \"恭喜您，提交成功啦！\"}");
                return;
            }
            context.Response.Write("{msg: 0, msgbox: \"对不起，保存过程中发生错误！\"}");
            return;
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
